package com.springboot.test.web.app;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.springboot.test.common.enums.StaticKey;
import com.springboot.test.common.response.Response;
import com.springboot.test.service.TradeRecordService;
import com.springboot.test.service.param.pageparam.BasePageParam;
import com.springboot.test.service.result.TradeRecordResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("app/trade")
public class TradeRecordController {

    @Resource
    private TradeRecordService tradeRecordService;

    @GetMapping("pay")
    public Response<Boolean> pay(@RequestAttribute(StaticKey.USER_CODE)String userCode,String goodsCode){
        return Response.success(tradeRecordService.pay(userCode,goodsCode));
    }

    @GetMapping("confirm_trade")
    public Response<Boolean> trade(@RequestAttribute(StaticKey.USER_CODE)String userCode,String goodsCode){
        return Response.success(tradeRecordService.confirmTrade(userCode,goodsCode));
    }

    @PostMapping("page")
    public Response<Page<TradeRecordResult>> page(@RequestAttribute(StaticKey.USER_CODE)String userCode, @RequestBody BasePageParam param){
        return Response.success(tradeRecordService.pageResult(userCode,param));
    }

    @GetMapping("cancel_trade")
    public Response<Boolean> cancelTrade(@RequestAttribute(StaticKey.USER_CODE)String userCode,String goodsCode){
        return Response.success(tradeRecordService.cancelTrade(userCode,goodsCode));
    }


}
